package asteroids.model.programs.Statement;


import asteroids.model.programs.Program;
import asteroids.model.programs.Type;
import asteroids.model.programs.Expression.Expression;
import asteroids.model.programs.Expression.IDoubleExpression;
import asteroids.model.programs.Expression.VariableLiteral;

/**
* 
* @version 0.3
* @author  Tandan Sunil, Van Deun Luca
*
*/
public class TurnAction extends ActionStatement {

	public TurnAction(int line, int column,Expression exp) {
		super(line, column);
		if(!canHaveAsExpression(exp))
			throw new IllegalArgumentException();
		this.exp = (IDoubleExpression) exp;
	}
	private IDoubleExpression exp;
	public boolean canHaveAsExpression(Expression exp){
		return (exp instanceof VariableLiteral || exp.getType().getType()==Type.AllType.DOUBLE);
	}
	
	public double getValue(){
		return exp.getValue();
	}
	
	@Override
	public void execute(Program program) {
		if(!haveWaited()){
		program.getOwner().addAngle(getValue());
		setWaited(true);
		}
		else
		setExecuted(true);
		
	}
}
